<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理</title>
    <link rel="stylesheet" href="../assets/bootstrap.min.css">
</head>

<body>
<!-- 弹出框 -->
<div class="modal fade" id="addRolePop" tabindex="-1" aria-labelledby="addRolePopLa" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="addRolePopLa">添加用户</h5>
                <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form class="d-grid gap-3" id="addRoleForm">
                    <input type="hidden" id="clientId">
                    <div class="form-group row">
                        <label class="col-md-3 col-form-label" for="myFile">用户头像</label>
                        <div class="col-md-8">
                            <label for="myFile"><img id="rolePhoto" src="../picture/none.png" alt=""
                                                     style="height: 60px;width: 60px"/></label>
                            <input type="file" id="myFile" accept="image/*" hidden="hidden"/>
                            <label for="myFile" id="myFileText"
                                   style="color: red;display: none">上传文件大小应小于3MB</label>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label" for="clientUsername">用户账号</label>
                        <div class="col-sm-8">
                            <input class="form-control" id="clientUsername" type="text" placeholder="用户账号">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-md-3 col-form-label" for="clientName">用户姓名</label>
                        <div class="col-md-8">
                            <input class="form-control" id="clientName" type="text" autocomplete="off"
                                   placeholder="用户姓名">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">性别</label>
                        <div class="col-sm-6">
                            <input class="btn-check" name="clientGender" id="clientGender_1" type="radio"
                                   autocomplete="off"
                                   checked>
                            <label class="btn btn-outline-success" for="clientGender_1">男</label>
                            <input class="btn-check" name="clientGender" id="clientGender_2" type="radio"
                                   autocomplete="off">
                            <label class="btn btn-outline-success" for="clientGender_2">女</label>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-md-3 col-form-label" for="clientTel">邮箱</label>
                        <div class="col-md-8">
                            <input class="form-control" id="clientTel" type="email" placeholder="联系方式">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label" for="clientAge">出生日期</label>
                        <div class="col-sm-8">
                            <input class="form-control" id="clientAge" type="date">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label" for="clientInfo">用户简介</label>
                        <div class="col-sm-8">
                            <input class="form-control" id="clientInfo" type="text" placeholder="用户简介">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-secondary" data-bs-dismiss="modal" type="button">关闭</button>
                <button class="btn btn-primary" data-bs-dismiss="modal" type="button" id="submitForm">确认提交</button>
            </div>
        </div>
    </div>
</div>
<!-- 搜索与添加与批量删除 -->
<nav class="navbar bg-light sticky-top">
    <div class="container-fluid">
        <form class="d-flex" role="search" onsubmit="return false">
            <input class="form-control me-2" type="search" placeholder="用户名字" aria-label="Search" id="searchInput">
            <button class="btn btn-outline-success" type="submit" onclick="sss.getAll()">Search</button>
        </form>
        <div class="d-flex flex-row-reverse bd-highlight">
            <button type="button" class="btn btn-danger ms-1" id="delALL">批量删除</button>
            <button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#addRolePop"
                    onclick="sss.addTit()">添加用户
            </button>
        </div>
    </div>
</nav>
<!-- 表格 -->
<table class="table table-striped table-bordered table-hover">
    <thead>
    <tr>
        <th><input class="form-check-input ms-3" type="checkbox" id="checkALL"><label for="checkALL"></label></th>
        <th>图片</th>
        <th>账号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>邮箱</th>
        <th>年龄</th>
        <th>简介</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tb-main">
    </tbody>
</table>
</body>
<script src="../assets/bootstrap.bundle.min.js"></script>
<script src="../assets/axios.js"></script>
<script src="z-myJS.js"></script>
<script type="text/javascript">
    const bbb = new MixImg()//重写方法
    class MixRole2 extends MixRole {
        addTit() {
            super.addTit()
            bbb.change('')
        }// 修改标题
        upTit(h) {
            bbb.change('')
            super.upTit(h);
        }
    }// 建立对象
    const sss = new MixRole2("client", "用户")
    window.onload = function () {
        sss.getAll();
    }// 向表格类动态添加数据
    function getDataRow(h) {
        const row = document.createElement('tr'); //创建行
        const {clientId, clientUsername, clientName, clientGender, clientTel, clientAge, clientInfo, clientPhoto} = h
        // 添加复选框
        row.appendChild(sss.check(clientId));
        // 信息展示
        const group = [sss.img(clientPhoto), clientUsername, clientName, clientGender ? "男" : "女", clientTel, sss.age(clientAge), clientInfo];
        for (const key of group) {
            row.appendChild(sss.cell(key))
        }
        //删除与修改按钮
        row.appendChild(sss.opCell(clientId, h));
        return row;
    }//表单数据转json
    function formToJson() {
        const group = ["clientId", "clientUsername", "clientName",
            "clientTel", "clientAge", "clientInfo"]
        const json = {
            "clientGender": document.getElementById("clientGender_1").checked,
            "clientPhoto": bbb.myImg
        }
        return Object.assign(sss.getVal(group), json)
    }//json数据转表单
    function jsonToForm(h) {
        const {clientGender, clientPhoto} = h
        const group = ["clientId", "clientUsername", "clientName",
            "clientTel", "clientAge", "clientInfo"]
        sss.setVal(group, h)
        sss.setSex(clientGender, "clientGender")
        bbb.change(clientPhoto)
    }
</script>

</html>